#pragma once
#include <vector>
#include "IRunnable.h"

namespace bs
{
	class IRenderable
	{
	public:
		virtual void Render(HDC dc) = 0;
	};

	class ICanvas
	{
	public:
		virtual HDC PrepareToDraw() = 0;        // return the dc to paint
		virtual void FlushToScreen() = 0; 
	};

	enum RenderLayer
	{
		RL_BOTTOM = 30,
		RL_MID = 60,
		RL_TOP = 90
	};

	class RenderProcess : public IRunnable
	{
	public:
		RenderProcess(ICanvas& canvas);
		~RenderProcess();

		virtual void Run(int id, size_t time, size_t frames, size_t elapse, void* userData);

		void AddRenderer(IRenderable* renderer, int renderLayer);
		void RemoveRenderer(IRenderable* renderer);

	private:
		struct RenderInfo
		{
			RenderInfo(IRenderable* r, int l) : renderer(r), renderLayer(l) {}

			bool operator >= (RenderInfo& other)
			{
				return this->renderLayer > other.renderLayer;
			}

			bool operator < (RenderInfo& other)
			{
				return !(*this >= other);
			}

			IRenderable* renderer;
			int renderLayer;
		};

	private:
		std::vector<RenderInfo*> renderInfos;

		ICanvas& canvas;
	};

}